<template>
	<div class="app-container">
		<!-- 顶部header区域 -->
		<mt-header fixed title="I LOVE YOU">
			<!-- slot="left"表示放在左边 -->
			<span slot="left" @click="goback" v-show="!flag">
				<mt-button icon="back">返回</mt-button>
			</span>
		</mt-header>
		<!-- 中间的router-view区域 -->
		<!-- 使用transition设置进出动画 -->
		<transition>
			<router-view></router-view>
		</transition>
		<!-- 底部的tabbar区域 -->
		<nav class="mui-bar mui-bar-tab">
			<router-link class="mui-tab-item" to="/home">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</router-link>
			<router-link class="mui-tab-item" to="/member">
				<span class="mui-icon mui-icon-email"></span>
				<span class="mui-tab-label">会员</span>
			</router-link>
			<router-link class="mui-tab-item" to="/shopcar">
				<span class="mui-icon mui-icon-extra mui-icon-extra-cart">
					<!-- 在花括号内调用main.js中的getter的方法获得购物车商品数量 -->
					<span class="mui-badge">{{this.$store.getters.getAllcount}}</span></span>
				<span class="mui-tab-label">购物车</span>
			</router-link>
			<router-link class="mui-tab-item" to="/search">
				<span class="mui-icon mui-icon-search"></span>
				<span class="mui-tab-label">搜索</span>
			</router-link>
		</nav>
	</div>
</template>

<script>
	export default{
		data(){
			return{
				flag:false,
			}
		},
		// 刚进入网站就要判断
		created(){
			this.flag=this.$route.path==='/home' ? true : false
		},
		methods:{
			goback(){
				this.$router.go(-1);
			}
		},
		watch:{
			// 监听到首页就不显示返回按钮了
			'$route.path':function(newVal){
				if(newVal=='/home'){
					this.flag=true;
				}else{
					this.flag=false;
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	mint-header{
		// 把头部的等级提高，防止懒加载图片列表区域可以拖走
		z-index: 99;
	}
	.app-container{
		/* 顶部的定位是fixed，被钉死在顶部，后续元素要想不和他重叠就需要隔开距离 */
		padding-top: 40px;
		padding-bottom: 50px;
		overflow-x: hidden;
	}
	.v-enter{
		opacity: 0;
		// 为了防止切页，进入就100%
		transform: translateX(100%);
	}
	.v-leave-to{
		// 离开的时候-100%，使得离开和进入方向一样，但是位置不同，-1,1这样中间有0,
		opacity: 0;
		transform: translateX(-100%);
		position: absolute;
	}
	.v-enter-active,.v-leave-active{
		transition: all 0.5s ease;
	}
	
</style>
